package com.txz.web.controller.common;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMethod;
import com.txz.common.config.TxzConfig;
import com.txz.common.core.domain.AjaxResult;
import java.io.File;

/**
 * 图片列表调试控制器
 */
@RestController
@RequestMapping("/debug/images")
public class ImageListDebugController {

    /**
     * 列出images目录中的所有文件
     */
    @GetMapping("/list")
    public AjaxResult listFiles() {
        String uploadPath = TxzConfig.getUploadPath();
        File imagesDir = new File(uploadPath + "/images");

        if (!imagesDir.exists() || !imagesDir.isDirectory()) {
            return AjaxResult.error("images目录不存在");
        }

        File[] files = imagesDir.listFiles();
        if (files == null || files.length == 0) {
            return AjaxResult.success("images目录为空");
        }

        StringBuilder sb = new StringBuilder();
        sb.append("images目录中的文件:\n");

        for (File file : files) {
            sb.append(file.getName()).append(" (").append(file.length()).append(" bytes)\n");
        }

        return AjaxResult.success(sb.toString());
    }
}
